package com.yhm.myfootbollshow.demos.config;

import com.yhm.myfootbollshow.demos.Interceptor.JWTInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @description:
 * @author: yhm
 * @time: 2024/03/05 14:28
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Value("${upload.path}")
    private String uploadPath;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new JWTInterceptor())
                .addPathPatterns("/yhm/user/")
                .excludePathPatterns("/user/**");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 将外部目录映射为静态资源访问路径
        registry.addResourceHandler("/uploads/**", "/yhm/uploads/**")
                .addResourceLocations("file:" + uploadPath + "/");
    }
}
